package com.speed_run.utils;

import org.apache.shiro.crypto.RandomNumberGenerator;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.apache.shiro.util.ByteSource;

import com.speed_run.model.UserAuth;

/**
 * 密碼加工類
 * @author wafer
 *
 */
public class PasswordHelper {
	private RandomNumberGenerator random = new  SecureRandomNumberGenerator();
	private final String algorithmName = "md5";
	private final int hashIterations = 2;
	
	/**
	 * 做加盐处理
	 * @param auth
	 */
	public void encryptPassword(UserAuth auth){
		//auth.setSalt(random.nextBytes().toHex());;
		auth.setAuthPwd(new SimpleHash(algorithmName, auth.getAuthPwd(),ByteSource.Util.bytes(auth.getAuthId()), hashIterations).toHex());
	}

	public static void main(String[] args) {
		System.out.println(new SimpleHash("md5", "admin",ByteSource.Util.bytes("admin"), 2).toHex());
	}
}
